﻿using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Read.API.Application.Commends.W.realize;

namespace MyMES.Read.API.Application.CommendHandlers.W.realize
{
    public class GetSupplierLevelCommandHanders : IRequestHandler<GetSupplierLevelCommands, APIResult<List<SupplierLevel>>>
    {
        private readonly IBaseRepository<SupplierLevel> supplierlevelRepository;

        public GetSupplierLevelCommandHanders(IBaseRepository<SupplierLevel> supplierlevelRepository)
        {
            this.supplierlevelRepository = supplierlevelRepository;
        }

        /// <summary>
        /// 显示等级下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<SupplierLevel>>> Handle(GetSupplierLevelCommands request, CancellationToken cancellationToken)
        {
            APIResult<List<SupplierLevel>> result = new APIResult<List<SupplierLevel>>();
            result.Code=APIEnum.查询成功;
            result.Msg = "查询成功";
            string sql = "select * from SupplierLevel";
            var list = await supplierlevelRepository.SelectAsync(sql);
            result.data = list;
            return result;
        }
    }
}
